package main

import (
	"fmt"
	"sync"
)

var wg sync.WaitGroup

func hello(i int) {
	fmt.Println("main go", i)
	wg.Done() //标识执行完该任务,通知wg把计数器-1
}

//并发
func main() {

	wg.Add(10000)
	for i := 0; i < 10000; i++ {
		go hello(i)

	}
	//开启独立的goroutine去执行hello函数
	//time.Sleep(time.Second) //等待一秒

	fmt.Println("go main")
	wg.Wait() //阻塞，等待减到0
}
